home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
varia
/
interp18.lha
/
interp-1.8
/
util.cc
< prev
Wrap
C/C++ Source or Header
|
1990-01-20
|
2KB
|
102 lines
// util.cc -- utility routines for the parser.
// Copyright (C) 1989 Carey Richard Murphey.
// (rich@rice.edu) 5310 Rutherglenn, Houston, TX 77096
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 1, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stream.h>
#include <math.h>
#include <ctype.h>
#include "parser.h"
Double_Pointer d (0.);
StringSymbolpAVLMap global_table (& d); // global symbol table
Context context (&global_table); // the set of symbol tables
int
yyerror (const char *const s)
{
cerr << "// " << s << '\n';
return 0;
}
t_func* print_table;
double
print_table (double x)
{
cerr << "\t\t\t// the contents of the symbol table:\n";
for (Pix ind = global_table.first(); ind; global_table.next(ind))
{
cerr << "\t// " << global_table.key(ind) << " = ";
global_table.contents(ind)->echo(cerr);
cerr << "\n";
}
cerr << "\t\t\t// end of symbol table.\n";
return 0.;
}
t_func* print_value;
double
print_value (double x)
{
cerr << "\t// " << x << "\n";
return x;
}
struct init
{
char *fname;
t_func* fnct;
};
struct init builtin[] =
{
"acos", acos,
"asin", asin,
"atan", atan,
"ceil", ceil,
"cos", cos,
"cosh", cosh,
"exp", exp,
"fabs", fabs,
"floor", floor,
"gamma", gamma,
"j0", j0,
"j1", j1,
"ln", log,
"log", log,
"log10", log10,
"sin", sin,
"sinh", sinh,
"sqrt", sqrt,
"tan", tan,
"tanh", tanh,
"y0", y0,
"y1", y1,
"print_table", print_table,
"print_value", print_value,
0, 0
};
void
init_parser ()
{
for (int i = 0; builtin[i].fname; i++)
global_table[builtin[i].fname] = new Function (builtin[i].fnct);
}